package cn.izeno.wx.models.mp


class QrCodeParam private constructor() : HashMap<String, Any>() {

  val token: String
    get() = this["token"] as String

  companion object {
    /**
     * 临时二维码
     */
    fun scene(token: String, expiredSeconds: Int, sceneId: Int): QrCodeParam {
      if (expiredSeconds > 2592000) throw IllegalArgumentException("expiredSeconds 最大为30天(2592000 s)")

      val param = QrCodeParam()

      param["token"] = token
      param["action_name"] = "QR_SCENE"
      param["expire_seconds"] = expiredSeconds

      val scene = HashMap<String, Any>()
      scene["scene_id"] = sceneId
      val actionInfo = HashMap<String, Any>()
      actionInfo["scene"] = scene
      param["action_info"] = actionInfo

      return param
    }

    /**
     * 临时字符串二维码
     * @param expiredSeconds 有效时间，以秒为单位。 最大不超过2592000（即30天。
     * @param sceneStr 场景值ID（字符串形式的ID），字符串类型，长度限制为1到64
     */
    fun scene(token: String, expiredSeconds: Int, sceneStr: String): QrCodeParam {
      if (expiredSeconds > 2592000) throw IllegalArgumentException("expiredSeconds 最大为30天(2592000 s)")

      val param = QrCodeParam()

      param["token"] = token
      param["action_name"] = "QR_STR_SCENE"
      param["expire_seconds"] = expiredSeconds

      val scene = HashMap<String, Any>()
      scene["scene_str"] = sceneStr
      val actionInfo = HashMap<String, Any>()
      actionInfo["scene"] = scene
      param["action_info"] = actionInfo

      return param
    }

    /**
     * 永久二维码
     * @param sceneId [1,10000]
     */
    fun limitScene(token: String, sceneId: Int): QrCodeParam {
      if (sceneId in 1..10000) throw IllegalArgumentException("sceneId must in [1,10000]")

      val param = QrCodeParam()

      param["token"] = token
      param["action_name"] = "QR_LIMIT_SCENE"

      val scene = HashMap<String, Any>()
      scene["scene_id"] = sceneId
      val actionInfo = HashMap<String, Any>()
      actionInfo["scene"] = scene
      param["action_info"] = actionInfo

      return param
    }

    /**
     * 永久二维码
     * @param sceneStr 场景值ID（字符串形式的ID），字符串类型，长度限制为1到64
     */
    fun limitScene(token: String, sceneStr: String): QrCodeParam {

      val param = QrCodeParam()

      param["token"] = token
      param["action_name"] = "QR_LIMIT_STR_SCENE"

      val scene = HashMap<String, Any>()
      scene["scene_str"] = sceneStr
      val actionInfo = HashMap<String, Any>()
      actionInfo["scene"] = scene
      param["action_info"] = actionInfo

      return param
    }
  }

}